package com.yunkaweilai.android.activity.member;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.bilibili.boxing.Boxing;
import com.bilibili.boxing.model.entity.BaseMedia;
import com.bilibili.boxing.model.entity.impl.ImageMedia;
import com.bilibili.boxing.utils.ImageCompressor;
import com.classic.common.MultipleStatusView;
import com.github.lazylibrary.util.StringUtils;
import com.google.gson.Gson;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.tools.PictureFileUtils;
import com.yunkaweilai.android.R;
import com.yunkaweilai.android.activity.CaptureActivity;
import com.yunkaweilai.android.activity.MemberActivity;
import com.yunkaweilai.android.base.BaseActivity;
import com.yunkaweilai.android.base.BaseApplication;
import com.yunkaweilai.android.constants.Api;
import com.yunkaweilai.android.constants.CommonConstants;
import com.yunkaweilai.android.fragment.member.WebFragment;
import com.yunkaweilai.android.interfaces.PopupAddMemberMoney;
import com.yunkaweilai.android.interfaces.PopupEmployeeInterfaces;
import com.yunkaweilai.android.interfaces.StringInterface;
import com.yunkaweilai.android.interfaces.StringTwoInterface;
import com.yunkaweilai.android.model.Event;
import com.yunkaweilai.android.model.ImageUploadModel;
import com.yunkaweilai.android.model.MemberAlbumModel;
import com.yunkaweilai.android.model.member.MemberDiyModel;
import com.yunkaweilai.android.model.member.MemberLevelModel;
import com.yunkaweilai.android.net.Glide.GlideUtils;
import com.yunkaweilai.android.net.HttpRequest;
import com.yunkaweilai.android.net.PostProcess;
import com.yunkaweilai.android.utils.ImageUtilsK;
import com.yunkaweilai.android.utils.InputMethodUtils;
import com.yunkaweilai.android.utils.PicturePickerHelper;
import com.yunkaweilai.android.utils.TitleBuilder;
import com.yunkaweilai.android.utils.Utils;
import com.yunkaweilai.android.utils.zxing.Kutils;
import com.yunkaweilai.android.view.OvalImageView;
import com.yunkaweilai.android.view.dialog.AddMemberDialog;
import com.yunkaweilai.android.view.dialog.member.MemberRecommenderDialog;
import com.yunkaweilai.android.view.popup.ImageEnlageAlbumPopup;
import com.yunkaweilai.android.view.popup.MemberAddMoneyPopup;
import com.yunkaweilai.android.view.popup.ShopEmployeePopup3;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import com.zhy.m.permission.MPermissions;
import com.zhy.m.permission.PermissionDenied;
import com.zhy.m.permission.PermissionGrant;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.addapp.pickers.listeners.OnItemPickListener;
import cn.addapp.pickers.listeners.OnSingleWheelListener;
import cn.addapp.pickers.picker.DatePicker;
import cn.addapp.pickers.picker.SinglePicker;
import okhttp3.Call;

/**
 * 新增会员
 * Created by Administrator on 2017/6/22.
 */

public class AddMemberInfoActivity extends BaseActivity implements PopupAddMemberMoney, StringTwoInterface, PopupEmployeeInterfaces, StringInterface, RadioGroup.OnCheckedChangeListener {

    @BindView(R.id.id_edt_card_no)
    EditText idEdtCardNo;
    @BindView(R.id.id_img_code)
    ImageView idImgCode;
    @BindView(R.id.id_edt_spare_card_no)
    EditText idEdtSpareCardNo;
    @BindView(R.id.id_tv_card_level)
    TextView idTvCardLevel;
    @BindView(R.id.id_llayout_level)
    LinearLayout idLlayoutLevel;
    @BindView(R.id.id_tv_time)
    TextView idTvTime;
    @BindView(R.id.id_llayout_time)
    LinearLayout idLlayoutTime;
    @BindView(R.id.id_img_head)
    ImageView idImgHead;
    @BindView(R.id.id_llayout_head)
    LinearLayout idLlayoutHead;
    @BindView(R.id.id_edt_name)
    EditText idEdtName;
    @BindView(R.id.id_tv_sex)
    TextView idTvSex;
    @BindView(R.id.id_llayout_sex)
    LinearLayout idLlayoutSex;
    @BindView(R.id.id_edt_tel)
    EditText idEdtTel;
    @BindView(R.id.id_tv_birthday)
    TextView idTvBirthday;
    @BindView(R.id.id_llayout_birthday)
    LinearLayout idLlayoutBirthday;
    @BindView(R.id.id_tv_anniversary_day)
    TextView idTvAnniversaryDay;
    @BindView(R.id.id_llayout_anniversary_day)
    LinearLayout idLlayoutAnniversaryDay;
    @BindView(R.id.id_llayout_diy)
    LinearLayout idLlayoutDiy;
    @BindView(R.id.id_edt_password)
    EditText idEdtPassword;
    @BindView(R.id.id_edt_recommend_card)
    TextView idEdtRecommendCard;
    @BindView(R.id.id_tv_salesman)
    TextView idTvSalesman;
    @BindView(R.id.id_llayout_salesman)
    LinearLayout idLlayoutSalesman;
    @BindView(R.id.id_edt_remark)
    EditText idEdtRemark;
    @BindView(R.id.id_multipleStatusView)
    MultipleStatusView idMultipleStatusView;
    //卡级别
    public static final String MEMBER_LEVEL_NAME = "MEMBER_LEVEL_NAME";
    public static final String MEMBER_LEVEL_VALIDITY_TYPE = "MEMBER_LEVEL_VALIDITY_TYPE";
    public static final String MEMBER_LEVEL_VALIDITY = "MEMBER_LEVEL_TYPE";
    public static final String MEMBER_LEVEL_ID = "MEMBER_LEVEL_ID";
    public static final String MEMBER_LEVEL_PASSWORD = "MEMBER_LEVEL_PASSWORD";
    public static final String MEMBER_LEVEL_AMOUT = "MEMBER_LEVEL_AMOUT";
    @BindView(R.id.id_llayout_password)
    LinearLayout idLlayoutPassword;
    @BindView(R.id.id_view_password)
    View idViewPassword;
    @BindView(R.id.id_edt_car_no)
    EditText idEdtCarNo;
    @BindView(R.id.content_view)
    ScrollView contentView;
    @BindView(R.id.titlebar_iv_left)
    ImageView titlebarIvLeft;
    @BindView(R.id.titlebar_tv_left)
    TextView titlebarTvLeft;
    @BindView(R.id.titlebar_tv)
    TextView titlebarTv;
    @BindView(R.id.titlebar_iv_right_2)
    ImageView titlebarIvRight2;
    @BindView(R.id.titlebar_iv_right)
    ImageView titlebarIvRight;
    @BindView(R.id.titlebar_tv_right)
    TextView titlebarTvRight;
    @BindView(R.id.id_view_underline)
    View idViewUnderline;
    @BindView(R.id.rl_titlebar)
    RelativeLayout rlTitlebar;
    @BindView(R.id.id_llayout_album)
    LinearLayout idLlayoutAlbum;
    @BindView(R.id.id_img1)
    OvalImageView idImg1;
    @BindView(R.id.id_img2)
    OvalImageView idImg2;
    @BindView(R.id.id_img3)
    OvalImageView idImg3;
    @BindView(R.id.id_img4)
    OvalImageView idImg4;
    @BindView(R.id.id_llayout_first_img)
    LinearLayout idLlayoutFirstImg;
    @BindView(R.id.id_img5)
    OvalImageView idImg5;
    @BindView(R.id.id_img6)
    OvalImageView idImg6;
    @BindView(R.id.id_llayout_next_img)
    LinearLayout idLlayoutNextImg;
    @BindView(R.id.id_tv_add_tel)
    TextView idTvAddTel;
    @BindView(R.id.fragment_container)
    FrameLayout frameLayout;
    @BindView(R.id.id_group)
    RadioGroup idGroup;
    @BindView(R.id.id_rbtn_1)
    RadioButton idRbtn1;
    @BindView(R.id.id_rbtn_2)
    RadioButton idRbtn2;
    @BindView(R.id.id_view1)
    View idView1;
    @BindView(R.id.id_view2)
    View idView2;
    @BindView(R.id.group_message_btn_right)
    Button ButtonRight;
    //卡锁定的几个view
    @BindView(R.id.id_llayout_lock)
    LinearLayout idLineLock;
    @BindView(R.id.id_tv_card_lock)
    TextView idTvLock;
    @BindView(R.id.id_img_card_lock)
    ImageView idImgLock;
    @BindView(R.id.id_view_lock)
    View idViewLock;

    private String status = "1";
    private LayoutInflater inflater;
    private WebFragment webFragment;
    private ArrayList<MemberDiyModel.DataBean.ListBean> diyList = new ArrayList<>();

    private Handler handler = new Handler();
    //时间
    private int mYear;
    private int mMonth;
    private int mDay;
    private boolean isChangeTime = true;
    //文件路径
    private String card_no = "";//卡号
    private boolean single_card_no = false;//卡号是否存在
    private String spare_card_no = "";//备用卡号
    private String mPicPath = "";
    private String member_avatar = "";
    private String member_sex = "male";
    private String is_sparecard_no = "0";
    private String level_id = "";
    private String member_birthday = "";
    private String member_anniversary = "";
    private Map<String, String> diymap = new HashMap<>();
    private String is_password = "";
    private float activate_amount = 0;
    private ArrayList<MemberAlbumModel> albumlist = new ArrayList<>();
    private String verification_no = "0";
    public static String ORDER_ID = "ORDER_ID";
    private String orderid;
    /**
     * 延迟线程，看是否还有下一个字符输入
     */
    private Runnable CardNoRun = new Runnable() {
        @Override
        public void run() {
            //在这里调用服务器的接口，获取数据
            checkCardNo();
        }
    };
    private Runnable SpareCardNoRun = new Runnable() {
        @Override
        public void run() {
            //在这里调用服务器的接口，获取数据
            checkSpareCardNo();
        }
    };

    public static void actionStart(Context context, String orderid) {
        Intent intent = new Intent(context, AddMemberInfoActivity.class);
        intent.putExtra(ORDER_ID, orderid);
        context.startActivity(intent);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_member);
        ButterKnife.bind(this);
        new TitleBuilder(this).setTitleText("新加会员").setLeftImage(R.mipmap.ic_go_back)
                .setLeftOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                        InputMethodUtils.closeSoftKeyboard(mAc);
                    }
                });
        idGroup.setOnCheckedChangeListener(this);
        idRbtn1.setChecked(true);
        if (getIntent() != null) {
            orderid = getIntent().getStringExtra(ORDER_ID);
        }
        inflater = this.getLayoutInflater();
        idMultipleStatusView.showLoading();
        initHttp(); //新增会员自定义属性
        initClick();
        initDate();
        setLevel();
    }

    //验证参数是否完全
    private void isRight() {
        if (StringUtils.isEmpty(card_no)) {
            showToast("卡号不能为空");
            return;
        }
        if (card_no.equals(spare_card_no)) {
            showToast("卡号与备用卡号不能相同");
            return;
        }
        if (StringUtils.isEmpty(level_id)) {
            showToast("还未选择卡等级");
            return;
        }

        if (StringUtils.isEmpty(idTvTime.getText().toString())) {
            showToast("还未选择有效期");
            return;
        }
        if (!StringUtils.isEmpty("") && !(idEdtTel.getText().toString().length() == 11)) {
            showToast("请填写正确的手机号");
            return;
        }
        if (!single_card_no) {
            showToast("卡号已存在");
            return;
        }
        if (activate_amount > 0) {
            MemberAddMoneyPopup memberAddMoneyPopup = new MemberAddMoneyPopup(mAc, activate_amount);
            memberAddMoneyPopup.setMemberMoney(this);
            memberAddMoneyPopup.showPopupWindow();
        } else {
            AddMemberDialog dialog = new AddMemberDialog(mAc, AddMemberInfoActivity.this, "");
            dialog.setCanceledOnTouchOutside(false);
            dialog.show();
//            showProgressDialog("请稍等，正在添加会员");
//            initAddMember("0", "");
        }
    }

    private void setLevel() {
        HttpRequest.postUrl(Api.MEMBER_LEVEL_LIST)
                .execute(new PostProcess.StringCallBack() {
                    @Override
                    public void onResponse(String json) {
                        boolean checkCode = Utils.checkCode(mAc, json);
                        if (checkCode) {
                            initDate();
                            Gson gson = new Gson();
                            MemberLevelModel memberLevelModel = gson.fromJson(json, MemberLevelModel.class);
                            if (memberLevelModel.getData().getList().size() > 0) {
                                MemberLevelModel.DataBean.ListBean listBean = memberLevelModel.getData().getList().get(0);
                                activate_amount = listBean.getActivate_amount();
                                String level_name = listBean.getLevel_name();
                                String level_time_type = listBean.getValidity_type();
                                long level_time = listBean.getValidity();
                                level_id = listBean.getId();
                                is_password = listBean.getIs_password();
                                if ("0".equals(is_password)) {
                                    showPassword(false);
                                } else if ("1".equals(is_password)) {
                                    showPassword(true);
                                }
                                idTvCardLevel.setText(level_name);
                                idTvCardLevel.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
                                String times = "";
                                switch (level_time_type) {
                                    case "permanent":
                                        times = "永久有效";
                                        isChangeTime = false;
                                        break;
                                    case "appoint"://指定时间
                                        times = Kutils.getDay(level_time);
                                        isChangeTime = true;
                                        break;
                                    case "year":
                                        mYear = (int) (mYear + level_time);
                                        times = mYear + "-" + mMonth + "-" + mDay;
                                        isChangeTime = true;
                                        break;
                                    case "month":
                                        mMonth = (int) (mMonth + level_time);
                                        while (mMonth > 12) {
                                            mMonth = mMonth - 12;
                                            mYear++;
                                        }
                                        times = mYear + "-" + mMonth + "-" + mDay;
                                        isChangeTime = true;
                                        break;
                                    case "day":
                                        mDay = (int) (mDay + level_time);
                                        while (mDay > Utils.MaxDayFromDay_OF_MONTH(mYear, mMonth)) {
                                            mDay = mDay - Utils.MaxDayFromDay_OF_MONTH(mYear, mMonth);
                                            mMonth++;
                                        }
                                        while (mMonth > 12) {
                                            mMonth = mMonth - 12;
                                            mYear++;
                                        }
                                        times = mYear + "-" + mMonth + "-" + mDay;
                                        isChangeTime = true;
                                        break;
                                    default:
                                        isChangeTime = true;
                                        break;
                                }
                                idTvTime.setText(times);
                                idTvTime.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
                            }
                        } else {
                        }
                    }

                    @Override
                    public void onError(Exception e) {
                    }
                });
    }

    //添加会员接口
    private void initAddMember(String payment, String type) {
        PostProcess postProcess = HttpRequest.postUrl(Api.ADD_MEMBER_INFO)
                .addParams("card_no", card_no)
                .addParams("is_sparecard_no", is_sparecard_no)
                .addParams("sparecard_no", spare_card_no)
                .addParams("level_id", level_id)
                .addParams("pay_password", idEdtPassword.getText().toString() + "")
                .addParams("member_name", idEdtName.getText().toString() + "")
                .addParams("member_sex", member_sex)
                .addParams("member_tel", idEdtTel.getText().toString() + "")
                .addParams("member_birthday_type", "gong")
                .addParams("member_birthday", member_birthday)
                .addParams("member_remarks", idEdtRemark.getText().toString())
                .addParams("member_anniversary", member_anniversary)
                .addParams("member_avatar", member_avatar)
                .addParams("is_alwaysvalid", isChangeTime ? "0" : "1")
                .addParams("validtime", idTvTime.getText().toString())
                .addParams("SelectedEmployeeStr", employeeStr)
                .addParams("recommend_card_no", verification_no)
                .addParams("status", status)//卡的状态
                .addParams("payInfo[payment_type]", type)
                .addParams("payInfo[cash_price]", activate_amount + "")
                .addParams("payInfo[bank_price]", activate_amount + "")
                .addParams("payInfo[alipay_price]", activate_amount + "")
                .addParams("payInfo[wechat_price]", activate_amount + "")
                .addParams("plate_number", idEdtCarNo.getText().toString() + "")
                .addParams("payment", payment);
        Iterator iter = diymap.entrySet().iterator();//自定义字段
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            String key = (String) entry.getKey();
            String val = (String) entry.getValue();
            postProcess.addParams(key, val);
        }
        for (int i = 0; i < albumlist.size(); i++) {
            MemberAlbumModel memberAlbumModel = albumlist.get(i);
            postProcess.addParams("albumList[" + i + "][path]", memberAlbumModel.getPath());
            postProcess.addParams("albumList[" + i + "][id]", memberAlbumModel.getId() + "");
            postProcess.addParams("albumList[" + i + "][album_remark]", memberAlbumModel.getAlbum_remark());
        }
        postProcess.execute(new PostProcess.StringCallBack() {
            @Override
            public void onResponse(String json) {
                boolean checkCode = Utils.checkCode(mAc, json);
                if (checkCode) {
                    showToast("添加成功");
                    EventBus.getDefault().post(new Event.TypeEvent(CommonConstants.MEMBER_LIST, true));
                    //如果是从散客直接添加会员过来的，把该订单分配给该会员
                    if (orderid == null) {
                    } else {
                        sanketohuiyuan(card_no, orderid);
                    }
                    intent2Activity(MemberActivity.class);
                    finish();
                }
                dismissProgressDialog();
            }

            @Override
            public void onError(Exception e) {
                dismissProgressDialog();
            }
        });


    }

    //散客新建会员时方法
    private void sanketohuiyuan(String card_no, String tid) {
        HttpRequest.postUrl(Api.ADD_SANKE_MEMBER)
                .addParams("tid", tid)
                .addParams("card_no", card_no)
                .execute(new PostProcess.StringCallBack() {
                    @Override
                    public void onResponse(String json) {
                        boolean checkCode = Utils.checkCode(mAc, json);
                        if (checkCode) {

                        }
                    }

                    @Override
                    public void onError(Exception e) {
                        showToast(e.getMessage());
                    }
                });
    }

    private void initDate() {
        final Calendar c = Calendar.getInstance();
        c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
        mYear = c.get(Calendar.YEAR);// 获取当前年份
        mMonth = c.get(Calendar.MONTH) + 1;// 获取当前月份
        mDay = c.get(Calendar.DAY_OF_MONTH);// 获取当前月份的日期号码
    }

    private void initClick() {
        ButtonRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isRight();
            }
        });
        idEdtCardNo.setRawInputType(Configuration.KEYBOARD_QWERTY);
        idEdtSpareCardNo.setRawInputType(Configuration.KEYBOARD_QWERTY);
        idEdtCardNo.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (CardNoRun != null) {
                    //每次editText有变化的时候，则移除上次发出的延迟线程
                    handler.removeCallbacks(CardNoRun);
                }
                card_no = s.toString();
                //延迟800ms，如果不再输入字符，则执行该线程的run方法
                if (!StringUtils.isEmpty(card_no)) {
                    handler.postDelayed(CardNoRun, 800);
                }
            }
        });
        idEdtSpareCardNo.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (SpareCardNoRun != null) {
                    //每次editText有变化的时候，则移除上次发出的延迟线程
                    handler.removeCallbacks(SpareCardNoRun);
                }
                spare_card_no = s.toString();

                //延迟800ms，如果不再输入字符，则执行该线程的run方法
                if (!StringUtils.isEmpty(spare_card_no)) {
                    handler.postDelayed(SpareCardNoRun, 800);
                    is_sparecard_no = "1";
                } else {
                    is_sparecard_no = "0";
                }
            }
        });

        idTvAddTel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                idEdtTel.setText("" + idEdtCardNo.getText().toString());
            }
        });

    }

    //会员自定义栏目
    private void initHttp() {

        //显示会员锁定与否栏目
        if (BaseApplication.member_status.equals("1")) {
            idLineLock.setClickable(true);
            idLineLock.setVisibility(View.VISIBLE);
            idViewLock.setVisibility(View.VISIBLE);
            idImgLock.setVisibility(View.VISIBLE);
            idTvLock.setText("正常");
            status = "1";
        } else if (BaseApplication.member_status.equals("0")) {
            idLineLock.setClickable(false);
            idLineLock.setVisibility(View.VISIBLE);
            idViewLock.setVisibility(View.VISIBLE);
            idImgLock.setVisibility(View.GONE);
            idTvLock.setText("锁定");
            status = "2";

        }
        HttpRequest.postUrl(Api.ADD_MEMBER_CUSTOM_ATTRIBUTES)
                .execute(new PostProcess.StringCallBack() {
                    @Override
                    public void onResponse(String json) {
                        boolean checkCode = Utils.checkCode(mAc, json);
                        if (checkCode) {
                            initAddView(json);
                        }
                        if (idMultipleStatusView != null) {
                            idMultipleStatusView.showContent();
                            ButtonRight.setVisibility(View.VISIBLE);
                        }
                    }

                    @Override
                    public void onError(Exception e) {
                        if (idMultipleStatusView != null) {
                            idMultipleStatusView.showContent();
                            ButtonRight.setVisibility(View.VISIBLE);
                        }
                    }
                });
    }


    private void initAddView(String json) {
        Gson gson = new Gson();
        MemberDiyModel memberDiyModel = gson.fromJson(json, MemberDiyModel.class);
        diyList.clear();
        diyList.addAll(memberDiyModel.getData().getList());
        for (int i = 0; i < diyList.size(); i++) {
            MemberDiyModel.DataBean.ListBean listBean = diyList.get(i);
            LinearLayout view = null;
            if ("text".equals(listBean.getField_type())) {
                view = (LinearLayout) inflater
                        .inflate(R.layout.view_member_diy_edt, null);
                diyEdts(i, view);
            } else if ("select_time".equals(listBean.getField_type())) {
                view = (LinearLayout) inflater
                        .inflate(R.layout.view_member_diy_txt, null);
                diyTimes(i, view);
            } else if ("radio".equals(listBean.getField_type())) {
                view = (LinearLayout) inflater
                        .inflate(R.layout.view_member_diy_txt, null);
                diyRadio(i, view);
            } else if ("checkbox".equals(listBean.getField_type())) {
                view = (LinearLayout) inflater
                        .inflate(R.layout.view_member_diy_txt, null);
                diyCheck(i, view);
            }
            idLlayoutDiy.addView(view);
        }

    }

    private void diyCheck(int position, LinearLayout view) {
        ((TextView) view.findViewById(R.id.id_tv_name)).setText(diyList.get(position).getField_name());
        final TextView idTvContent = (TextView) view.findViewById(R.id.id_tv_content);
        idTvContent.setTag(position);
        idTvContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int tag = (int) v.getTag();
                checkboxSelector(diyList.get(tag).getField_content(), tag);
            }
        });
    }

    //diy单选
    private void diyRadio(final int position, LinearLayout view) {
        ((TextView) view.findViewById(R.id.id_tv_name)).setText(diyList.get(position).getField_name());
        final TextView idTvContent = (TextView) view.findViewById(R.id.id_tv_content);
        idTvContent.setTag(position);
        idTvContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int tag = (int) v.getTag();
                initPickerSingle(diyList.get(tag).getField_content(), tag);
            }
        });
    }

    //diy时间选择
    private void diyTimes(int position, LinearLayout view) {
        ((TextView) view.findViewById(R.id.id_tv_name)).setText(diyList.get(position).getField_name());
        final TextView idTvContent = (TextView) view.findViewById(R.id.id_tv_content);
        idTvContent.setTag(position);
        idTvContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                initDate();
                final int tag = (int) v.getTag();
                LinearLayout childAt = (LinearLayout) idLlayoutDiy.getChildAt(tag);
                final TextView viewById = (TextView) childAt.findViewById(R.id.id_tv_content);
                String s = viewById.getText().toString();
                if (s.contains("-")) {
                    String[] all = s.split("-");
                    mYear = Integer.parseInt(all[0]);
                    mMonth = Integer.parseInt(all[1]);
                    mDay = Integer.parseInt(all[2]);
                }
                final DatePicker picker = new DatePicker(mAc);
                picker.setCanLoop(false);
                picker.setWheelModeEnable(true);
                picker.setTopPadding(15);
                picker.setRangeStart(1930, 1, 01);
                picker.setRangeEnd(mYear + 100, 11, 11);
                picker.setSelectedItem(mYear, mMonth, mDay);
                picker.setWeightEnable(true);
                picker.setOnDatePickListener(new DatePicker.OnYearMonthDayPickListener() {
                    @Override
                    public void onDatePicked(String year, String month, String day) {

                        viewById.setText(year + "-" + month + "-" + day);
                        viewById.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
                        diymap.put("member_otherfield[" + diyList.get(tag).getId() + "]", year + "-" + month + "-" + day);
                    }
                });
                picker.setOnWheelListener(new DatePicker.OnWheelListener() {
                    @Override
                    public void onYearWheeled(int index, String year) {
                        picker.setTitleText(year + "-" + picker.getSelectedMonth() + "-" + picker.getSelectedDay());
                    }

                    @Override
                    public void onMonthWheeled(int index, String month) {
                        picker.setTitleText(picker.getSelectedYear() + "-" + month + "-" + picker.getSelectedDay());
                    }

                    @Override
                    public void onDayWheeled(int index, String day) {
                        picker.setTitleText(picker.getSelectedYear() + "-" + picker.getSelectedMonth() + "-" + day);
                    }
                });
                picker.show();
            }
        });
    }

    //处理diy文本信息
    private void diyEdts(final int position, LinearLayout view) {
        ((TextView) view.findViewById(R.id.id_tv_name)).setText(diyList.get(position).getField_name());
        EditText edtContent = (EditText) view.findViewById(R.id.id_edt_content);
        edtContent.setTag(position);
        edtContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                diymap.put("member_otherfield[" + diyList.get(position).getId() + "]", s.toString() + "");
            }
        });

    }

    //检验卡号是否存在
    private void checkCardNo() {
        HttpRequest.postUrl(Api.CHECKED_MEMBER_CARD_NO)
                .addParams("type", "cardno")
                .addParams("value", card_no)
                .execute(new PostProcess.StringCallBack() {
                    @Override
                    public void onResponse(String json) {
                        single_card_no = Utils.checkCode(mAc, json);
                    }

                    @Override
                    public void onError(Exception e) {

                    }
                });
    }

    //检验备用卡号是否存在
    private void checkSpareCardNo() {
        HttpRequest.postUrl(Api.CHECKED_MEMBER_CARD_NO)
                .addParams("type", "sparecardno")
                .addParams("value", spare_card_no)
                .execute(new PostProcess.StringCallBack() {
                    @Override
                    public void onResponse(String json) {
                        boolean checkCode = Utils.checkCode(mAc, json);
                        if (!checkCode) {
                            spare_card_no = "";
                        }
                        showLog(json);
                    }

                    @Override
                    public void onError(Exception e) {
                        spare_card_no = "";
                    }
                });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (data != null) {
                switch (requestCode) {
                    case 301://二维码
                        Bundle bundle = data.getExtras();
                        if (bundle == null) {
                            return;
                        }
                        String result = bundle.getString(CaptureActivity.RESULT);
                        idEdtCardNo.setText(result);
                        break;
                    case 302://会员级别有效期
                        initDate();
                        activate_amount = data.getFloatExtra(MEMBER_LEVEL_AMOUT, 0);
                        String level_name = data.getStringExtra(MEMBER_LEVEL_NAME);
                        String level_time_type = data.getStringExtra(MEMBER_LEVEL_VALIDITY_TYPE);
                        long level_time = data.getLongExtra(MEMBER_LEVEL_VALIDITY, 0);
                        level_id = data.getStringExtra(MEMBER_LEVEL_ID);
                        is_password = data.getStringExtra(MEMBER_LEVEL_PASSWORD);
                        if ("0".equals(is_password)) {
                            showPassword(false);
                        } else if ("1".equals(is_password)) {
                            showPassword(true);
                        }
                        idTvCardLevel.setText(level_name);
                        idTvCardLevel.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
                        String times = "";
                        switch (level_time_type) {
                            case "permanent":
                                times = "永久有效";
                                isChangeTime = false;
                                break;
                            case "appoint"://指定时间
                                times = Kutils.getDay(level_time);
                                isChangeTime = true;
                                break;
                            case "year":
                                mYear = (int) (mYear + level_time);
                                times = mYear + "-" + mMonth + "-" + mDay;
                                isChangeTime = true;
                                break;
                            case "month":
                                mMonth = (int) (mMonth + level_time);
                                while (mMonth > 12) {
                                    mMonth = mMonth - 12;
                                    mYear++;
                                }
                                times = mYear + "-" + mMonth + "-" + mDay;
                                isChangeTime = true;
                                break;
                            case "day":
                                mDay = (int) (mDay + level_time);
                                while (mDay > Utils.MaxDayFromDay_OF_MONTH(mYear, mMonth)) {
                                    mDay = mDay - Utils.MaxDayFromDay_OF_MONTH(mYear, mMonth);
                                    mMonth++;
                                }
                                while (mMonth > 12) {
                                    mMonth = mMonth - 12;
                                    mYear++;
                                }
                                times = mYear + "-" + mMonth + "-" + mDay;
                                isChangeTime = true;
                                break;
                            default:
                                isChangeTime = true;
                                break;
                        }
                        idTvTime.setText(times);
                        idTvTime.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
                        break;
                    case 303://头像
                        final ArrayList<BaseMedia> medias = Boxing.getResult(data);
                        BaseMedia baseMedia = medias.get(0);
                        if (!(baseMedia instanceof ImageMedia)) {
                            return;
                        }
                        showProgressDialog("请稍等，图片上传中...");
                        final ImageMedia imageMedia = (ImageMedia) baseMedia;
                        //对返回的图片进行压缩
                        if (imageMedia.compress(new ImageCompressor(this))) {
                            imageMedia.removeExif();
                        }

//                        //压缩质量和尺寸 上面这个不靠谱
                        File fileDir = Environment.getExternalStorageDirectory();
                        BitmapFactory.Options opts = new BitmapFactory.Options();
                        Bitmap bitmap = BitmapFactory.decodeFile(imageMedia.getPath(), opts);// 文件路径
                        ImageUtilsK.compressImage2File(bitmap, new File(fileDir, "AddMember.jpg"));
                        File file1 = new File(fileDir, "AddMember.jpg");
                        mPicPath = file1.getAbsolutePath();
//                        mPicPath = imageMedia.getPath();
                        uploadFile(mPicPath);
                        break;
                    case 305:
                        albumlist = (ArrayList<MemberAlbumModel>) data.getSerializableExtra(MemberAlbumActivity.ALBUM_LIST);
                        if (albumlist == null) {
                            albumlist = new ArrayList<>();
                        }
                        showImageIs(albumlist);
                        break;
                    case PictureConfig.CHOOSE_REQUEST://头像
                        String uri = PicturePickerHelper.onPickLogoOrAvatarActivityResult(requestCode, resultCode, data);
                        if (!StringUtils.isEmpty(uri)) {
                            uploadFile(uri);
                        } else {
                            showToast("未选择照片");
                        }
                        break;
                }
            }

        }
    }

    private void showImageIs(ArrayList<MemberAlbumModel> list) {
        if (list.size() > 0) {
            idLlayoutFirstImg.setVisibility(View.VISIBLE);
        } else {
            idLlayoutFirstImg.setVisibility(View.GONE);
        }
        if (list.size() > 4) {
            idLlayoutNextImg.setVisibility(View.VISIBLE);
        } else {
            idLlayoutNextImg.setVisibility(View.GONE);
        }
        switch (list.size()) {
            case 1:
                idImg1.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(0).getPath(), idImg1);
                idImg2.setVisibility(View.GONE);
                idImg3.setVisibility(View.GONE);
                idImg4.setVisibility(View.GONE);
                idImg5.setVisibility(View.GONE);
                idImg6.setVisibility(View.GONE);

                break;
            case 2:
                idImg1.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(0).getPath(), idImg1);
                idImg2.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(1).getPath(), idImg2);
                idImg3.setVisibility(View.GONE);
                idImg4.setVisibility(View.GONE);
                idImg5.setVisibility(View.GONE);
                idImg6.setVisibility(View.GONE);
                break;
            case 3:
                idImg1.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(0).getPath(), idImg1);
                idImg2.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(1).getPath(), idImg2);
                idImg3.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(2).getPath(), idImg3);
                idImg4.setVisibility(View.GONE);
                idImg5.setVisibility(View.GONE);
                idImg6.setVisibility(View.GONE);
                break;
            case 4:
                idImg1.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(0).getPath(), idImg1);
                idImg2.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(1).getPath(), idImg2);
                idImg3.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(2).getPath(), idImg3);
                idImg4.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(3).getPath(), idImg4);
                idImg5.setVisibility(View.GONE);
                idImg6.setVisibility(View.GONE);
                break;
            case 5:
                idImg1.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(0).getPath(), idImg1);
                idImg2.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(1).getPath(), idImg2);
                idImg3.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(2).getPath(), idImg3);
                idImg4.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(3).getPath(), idImg4);
                idImg5.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(4).getPath(), idImg5);
                idImg6.setVisibility(View.GONE);
                break;
            case 6:
                idImg1.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(0).getPath(), idImg1);
                idImg2.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(1).getPath(), idImg2);
                idImg3.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(2).getPath(), idImg3);
                idImg4.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(3).getPath(), idImg4);
                idImg5.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(4).getPath(), idImg5);
                idImg6.setVisibility(View.VISIBLE);
                GlideUtils.loadImage(mAc, list.get(5).getPath(), idImg6);
                break;
        }

    }


    public int MEMBER_CARD_QR_CODE = 301;//二维码
    public int MEMBER_LEVEL = 302;//会员级别
    public int MEMBER_HEAD_IMAGE = 303;//会员头像
    public int MEMBER_ALBUM_LIST = 305;//会员相册
    private String employeeStr = "";

    @OnClick({R.id.id_edt_recommend_card, R.id.id_llayout_album, R.id.id_img_code, R.id.id_llayout_level, R.id.id_llayout_time, R.id.id_llayout_head, R.id.id_llayout_sex, R.id.id_llayout_birthday, R.id.id_llayout_anniversary_day, R.id.id_llayout_salesman,
            R.id.id_img1, R.id.id_img2, R.id.id_img3, R.id.id_img4, R.id.id_img5, R.id.id_img6, R.id.id_llayout_lock})
    public void onViewClicked(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.id_edt_recommend_card:
                MemberRecommenderDialog dialog = new MemberRecommenderDialog(mAc, this);
                dialog.show();
                break;
            case R.id.id_llayout_album:
                intent = new Intent(mAc, MemberAlbumActivity.class);
                intent.putExtra(MemberAlbumActivity.ALBUM_LIST_GET_LIST, (Serializable) albumlist);
                startActivityForResult(intent, MEMBER_ALBUM_LIST);
                break;
            case R.id.id_img_code://扫码
                getCameraManifest();
                break;
            case R.id.id_llayout_level://级别
                startActivityForResult(new Intent(mAc, MemberLevelActivity.class), MEMBER_LEVEL);
                break;
            case R.id.id_llayout_time://有效期
                ArrayList<String> timelist = new ArrayList<>();
                timelist.add("永久有效");
                timelist.add("选择有效期");
                initTimeOrCard(timelist);
                break;
            case R.id.id_llayout_head://头像

                PicturePickerHelper.pickLogoOrAvatar(AddMemberInfoActivity.this);

//                String cachePath = BoxingFileHelper.getCacheDir(this);
//                if (TextUtils.isEmpty(cachePath)) {
//                    Toast.makeText(this, R.string.storage_deny, Toast.LENGTH_SHORT).show();
//                    return;
//                }
//                Uri destUri = new Uri.Builder()
//                        .scheme("file")
//                        .appendPath(cachePath)
//                        .appendPath(String.format(Locale.US, "%s.jpg", System.currentTimeMillis()))
//                        .build();
//                BoxingConfig singleCropImgConfig = new BoxingConfig(BoxingConfig.Mode.SINGLE_IMG).withCropOption(new BoxingCropOption(destUri).aspectRatio(1, 1)).needCamera();
//                Boxing.of(singleCropImgConfig).withIntent(this, PhotoPickerActivity.class).start(this, MEMBER_HEAD_IMAGE);

                break;
            case R.id.id_llayout_sex://性别
                ArrayList<String> list = new ArrayList<>();
                list.add("男");
                list.add("女");
                pickerSelSex(list);
                break;
            case R.id.id_llayout_birthday://生日
                idTvBirthday.setTag("birthday");
                initPickerData2(idTvBirthday);
                break;
            case R.id.id_llayout_anniversary_day://纪念日
                idTvAnniversaryDay.setTag("anniversary");
                initPickerData2(idTvAnniversaryDay);
                break;
            case R.id.id_llayout_lock:
                ArrayList<String> list1 = new ArrayList<>();
                list1.add("正常");
                list1.add("锁定");
                pickerLock(list1);
                break;
            case R.id.id_llayout_salesman://操作人

                ShopEmployeePopup3 shopPopup = new ShopEmployeePopup3(mAc, employeeStr, Api.PERECENTAGES_MEMBER_CARD, level_id);
                shopPopup.setInterface(AddMemberInfoActivity.this);
                shopPopup.showPopupWindow();

                break;
            case R.id.id_img1:
                if (albumlist.size() > 0) {
                    ImageEnlageAlbumPopup popup = new ImageEnlageAlbumPopup(mAc, albumlist.get(0).getPath(), R.mipmap.ic_image_add, albumlist.get(0).getAlbum_remark());
                    popup.showPopupWindow();
                }
                break;
            case R.id.id_img2:
                if (albumlist.size() > 1) {
                    ImageEnlageAlbumPopup popup = new ImageEnlageAlbumPopup(mAc, albumlist.get(1).getPath(), R.mipmap.ic_image_add, albumlist.get(1).getAlbum_remark());
                    popup.showPopupWindow();
                }
                break;
            case R.id.id_img3:
                if (albumlist.size() > 2) {
                    ImageEnlageAlbumPopup popup = new ImageEnlageAlbumPopup(mAc, albumlist.get(2).getPath(), R.mipmap.ic_image_add, albumlist.get(2).getAlbum_remark());
                    popup.showPopupWindow();
                }
                break;
            case R.id.id_img4:
                if (albumlist.size() > 3) {
                    ImageEnlageAlbumPopup popup = new ImageEnlageAlbumPopup(mAc, albumlist.get(3).getPath(), R.mipmap.ic_image_add, albumlist.get(3).getAlbum_remark());
                    popup.showPopupWindow();
                }
                break;
            case R.id.id_img5:
                if (albumlist.size() > 4) {
                    ImageEnlageAlbumPopup popup = new ImageEnlageAlbumPopup(mAc, albumlist.get(4).getPath(), R.mipmap.ic_image_add, albumlist.get(4).getAlbum_remark());
                    popup.showPopupWindow();
                }
                break;
            case R.id.id_img6:
                if (albumlist.size() > 5) {
                    ImageEnlageAlbumPopup popup = new ImageEnlageAlbumPopup(mAc, albumlist.get(5).getPath(), R.mipmap.ic_image_add, albumlist.get(5).getAlbum_remark());
                    popup.showPopupWindow();
                }
                break;
        }
    }


    //获取照相机权限
    private static final int MY_PERMISSIONS_REQUEST_CAMERA = 1;

    private void getCameraManifest() {
        MPermissions.requestPermissions(this, MY_PERMISSIONS_REQUEST_CAMERA, Manifest.permission.CAMERA);
    }

    private void getCamera() {
        Intent intent = new Intent(mAc, CaptureActivity.class);
        startActivityForResult(intent, MEMBER_CARD_QR_CODE);
    }

    @PermissionGrant(MY_PERMISSIONS_REQUEST_CAMERA)
    public void requestSuccess() {
        getCamera();
    }

    @PermissionDenied(MY_PERMISSIONS_REQUEST_CAMERA)
    public void requestError() {
        showToast("授权失败！");
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        MPermissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    }


    //时间选择
    private void initPickerData(final TextView tvView) {
        initDate();
        String s = tvView.getText().toString();
        if (s.contains("-")) {
            String[] all = s.split("-");
            mYear = Integer.parseInt(all[0]);
            mMonth = Integer.parseInt(all[1]);
            mDay = Integer.parseInt(all[2]);
        }
        final DatePicker picker = new DatePicker(this);
        picker.setCanLoop(false);
        picker.setWheelModeEnable(true);
        picker.setTopPadding(15);
        picker.setRangeStart(mYear - 70, 1, 01);
        picker.setRangeEnd(mYear + 70, 11, 11);
        picker.setSelectedItem(mYear, mMonth, mDay);
        picker.setWeightEnable(true);
        picker.setOnDatePickListener(new DatePicker.OnYearMonthDayPickListener() {
            @Override
            public void onDatePicked(String year, String month, String day) {
                String tag = (String) tvView.getTag();
                if ("times".equals(tag + "")) {
                    isChangeTime = true;
                }
                tvView.setText(year + "-" + month + "-" + day);
                tvView.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
                if ("birthday".equals(tag + "")) {
                    member_birthday = year + "-" + month + "-" + day;
                }
                if ("anniversary".equals(tag + "")) {
                    member_anniversary = year + "-" + month + "-" + day;
                }
            }
        });
        picker.setOnWheelListener(new DatePicker.OnWheelListener() {
            @Override
            public void onYearWheeled(int index, String year) {
                picker.setTitleText(year + "-" + picker.getSelectedMonth() + "-" + picker.getSelectedDay());
            }

            @Override
            public void onMonthWheeled(int index, String month) {
                picker.setTitleText(picker.getSelectedYear() + "-" + month + "-" + picker.getSelectedDay());
            }

            @Override
            public void onDayWheeled(int index, String day) {
                picker.setTitleText(picker.getSelectedYear() + "-" + picker.getSelectedMonth() + "-" + day);
            }
        });
        picker.show();
    }

    //时间选择
    private void initPickerData2(final TextView tvView) {
        initDate();
        String s = tvView.getText().toString();
        if (s.contains("-")) {
            String[] all = s.split("-");
            mMonth = Integer.parseInt(all[0]);
            mDay = Integer.parseInt(all[1]);
        }
        final DatePicker picker = new DatePicker(mAc, DatePicker.MONTH_DAY);
        picker.setCanLoop(false);
        picker.setWheelModeEnable(true);
        picker.setTopPadding(15);
        picker.setRangeStart(1, 01);
        picker.setRangeEnd(12, 31);
        picker.setSelectedItem(mMonth, mDay);
        picker.setWeightEnable(true);
        picker.setOnDatePickListener(new DatePicker.OnMonthDayPickListener() {
            @Override
            public void onDatePicked(String month, String day) {
                String tag = (String) tvView.getTag();
                if ("times".equals(tag + "")) {
                    isChangeTime = true;
                }
                if ("birthday".equals(tag + "")) {
                    member_birthday = month + "-" + day;
                }
                if ("anniversary".equals(tag + "")) {
                    member_anniversary = month + "-" + day;
                }
                tvView.setText(month + "-" + day);
                tvView.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
            }
        });
        picker.setOnWheelListener(new DatePicker.OnWheelListener() {
            @Override
            public void onYearWheeled(int index, String year) {
                picker.setTitleText(picker.getSelectedMonth() + "-" + picker.getSelectedDay());
            }

            @Override
            public void onMonthWheeled(int index, String month) {
                picker.setTitleText(month + "-" + picker.getSelectedDay());
            }

            @Override
            public void onDayWheeled(int index, String day) {
                picker.setTitleText(picker.getSelectedMonth() + "-" + day);
            }
        });
        picker.show();
    }


    //文件上传
    private void uploadFile(final String mPicPath) {
        Map<String, String> paprms = new HashMap<>();
        paprms.put("token", BaseApplication.getToken());

        OkHttpUtils.post().addFile("file", "shop.jpg", new File(mPicPath))
                .url(Api.IMAGE_UPLOAD).params(paprms).build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dismissProgressDialog();
                        showToast("上传失败");
                    }
                });
            }

            @Override
            public void onResponse(final String response, int id) {
                boolean isChecked = Utils.checkCode(mAc, response);
                final Gson gson = new Gson();
                if (!isChecked) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            dismissProgressDialog();
                        }
                    });
                } else {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            dismissProgressDialog();
                            ImageUploadModel imageUploadModel = gson.fromJson(response, ImageUploadModel.class);
                            member_avatar = imageUploadModel.getData().getPath();
                            GlideUtils.loadCircleImage(mAc, member_avatar, idImgHead);
                            PictureFileUtils.deleteCacheDirFile(AddMemberInfoActivity.this);//清除缓存
                        }
                    });
                }
            }
        });
    }

    //性别选择
    private void pickerSelSex(List<String> list) {
        SinglePicker<String> picker = new SinglePicker<>(this, list);
        picker.setCanLoop(false);//不禁用循环
        picker.setLineVisible(true);
        picker.setShadowVisible(true);
        picker.setTextSize(18);
        picker.setSelectedIndex(0);
        picker.setWheelModeEnable(true);
        //启用权重 setWeightWidth 才起作用
        picker.setWeightEnable(true);
        picker.setWeightWidth(1);
        picker.setSelectedTextColor(0xFF279BAA);//前四位值是透明度
        picker.setUnSelectedTextColor(0xFF999999);
        picker.setOnSingleWheelListener(new OnSingleWheelListener() {
            @Override
            public void onWheeled(int index, String item) {

            }
        });
        picker.setOnItemPickListener(new OnItemPickListener<String>() {
            @Override
            public void onItemPicked(int index, String item) {
                idTvSex.setText(item);
                idTvSex.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
                if (index == 0) {
                    member_sex = "male";
                } else if (index == 1) {
                    member_sex = "famale";
                }

            }
        });
        picker.show();
    }

    //锁定选择
    private void pickerLock(List<String> list) {
        SinglePicker<String> picker = new SinglePicker<>(this, list);
        picker.setCanLoop(false);//不禁用循环
        picker.setLineVisible(true);
        picker.setShadowVisible(true);
        picker.setTextSize(18);
        picker.setSelectedIndex(0);
        picker.setWheelModeEnable(true);
        //启用权重 setWeightWidth 才起作用
        picker.setWeightEnable(true);
        picker.setWeightWidth(1);
        picker.setSelectedTextColor(0xFF279BAA);//前四位值是透明度
        picker.setUnSelectedTextColor(0xFF999999);
        picker.setOnSingleWheelListener(new OnSingleWheelListener() {
            @Override
            public void onWheeled(int index, String item) {

            }
        });
        picker.setOnItemPickListener(new OnItemPickListener<String>() {
            @Override
            public void onItemPicked(int index, String item) {
                idTvLock.setText(item);
                if (index == 0) {
                    status = "1";
                } else if (index == 1) {
                    status = "2";
                }

            }
        });
        picker.show();
    }

    //单选处理
    private void initPickerSingle(List<String> list, final int position) {
        SinglePicker<String> picker = new SinglePicker<>(this, list);
        picker.setCanLoop(false);//不禁用循环
        picker.setLineVisible(true);
        picker.setShadowVisible(true);
        picker.setTextSize(18);
        picker.setSelectedIndex(0);
        picker.setWheelModeEnable(true);
        //启用权重 setWeightWidth 才起作用
        picker.setWeightEnable(true);
        picker.setWeightWidth(1);
        picker.setSelectedTextColor(0xFF279BAA);//前四位值是透明度
        picker.setUnSelectedTextColor(0xFF999999);
        picker.setOnSingleWheelListener(new OnSingleWheelListener() {
            @Override
            public void onWheeled(int index, String item) {


            }
        });
        picker.setOnItemPickListener(new OnItemPickListener<String>() {
            @Override
            public void onItemPicked(int index, String item) {
                LinearLayout childAt = (LinearLayout) idLlayoutDiy.getChildAt(position);
                TextView viewById = (TextView) childAt.findViewById(R.id.id_tv_content);
                viewById.setText(item);
                viewById.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
                diymap.put("member_otherfield[" + diyList.get(position).getId() + "]", item);
            }
        });
        picker.show();
    }

    //处理多选
    private void checkboxSelector(final ArrayList<String> list, final int position) {
        new MaterialDialog.Builder(this)
                .items(list)
                .itemsCallbackMultiChoice(
                        new Integer[]{}, new MaterialDialog.ListCallbackMultiChoice() {
                            @Override
                            public boolean onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
                                return which.length < 8;
                            }
                        })
                .positiveText("确定")
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Integer[] selectedIndices = dialog.getSelectedIndices();
                        String selector = "";
                        for (int i = 0; i < selectedIndices.length; i++) {
                            diymap.put("member_otherfield[" + diyList.get(position).getId() + "][" + i + "]", list.get(selectedIndices[i]));
                            if (i != 0) {
                                selector = selector + ",";
                            }
                            selector = selector + list.get(selectedIndices[i]);
                        }
                        LinearLayout childAt = (LinearLayout) idLlayoutDiy.getChildAt(position);
                        TextView viewById = (TextView) childAt.findViewById(R.id.id_tv_content);
                        viewById.setText(selector);
                        viewById.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
//                        String s = diymap.get("member_otherfield[" + diyList.get(position).getId() + "]");
//                        if ("".equals(s)){
//                        }else{
//                            diymap.remove("member_otherfield[" + diyList.get(position).getId() + "]");
//                        }
//                        diymap.put("member_otherfield[" + diyList.get(position).getId() + "]", selector);

                    }
                })
                .neutralText("取消")
                .onNeutral(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        dialog.dismiss();
                    }
                })
                .alwaysCallMultiChoiceCallback() // the callback will always be called, to check if (un)selection is still allowed
                .show();
    }

    //是否开启密码
    private void showPassword(boolean flag) {
        if (flag) {
            idLlayoutPassword.setVisibility(View.VISIBLE);
            idViewPassword.setVisibility(View.VISIBLE);
        } else {
            idLlayoutPassword.setVisibility(View.GONE);
            idViewPassword.setVisibility(View.GONE);
        }
    }

    @Override
    public void addMoney(String prcie, String type) {

        AddMemberDialog dialog = new AddMemberDialog(mAc, AddMemberInfoActivity.this, type);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();

    }

    //选择推荐人
    @Override
    public void getString(String verification_no, String name) {
        this.verification_no = verification_no + "";
        idEdtRecommendCard.setText(name + "");
        idEdtRecommendCard.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
    }


    //为了有效期单独开放
    private void initTimeOrCard(List<String> list) {
        SinglePicker<String> picker = new SinglePicker<>(this, list);
        picker.setCanLoop(false);//不禁用循环
        picker.setLineVisible(true);
        picker.setShadowVisible(true);
        picker.setTextSize(18);
        picker.setSelectedIndex(0);
        picker.setWheelModeEnable(true);
        //启用权重 setWeightWidth 才起作用
        picker.setWeightEnable(true);
        picker.setWeightWidth(1);
        picker.setSelectedTextColor(0xFF279BAA);//前四位值是透明度
        picker.setUnSelectedTextColor(0xFF999999);
        picker.setOnSingleWheelListener(new OnSingleWheelListener() {
            @Override
            public void onWheeled(int index, String item) {


            }
        });
        picker.setOnItemPickListener(new OnItemPickListener<String>() {
            @Override
            public void onItemPicked(int index, String item) {
                if ("选择有效期".equals(item)) {
                    idTvTime.setTag("times");
                    initPickerData(idTvTime);
                } else {
                    idTvTime.setText(item + "");
                    isChangeTime = false;
                }
            }
        });
        picker.show();
    }

    @Override
    public void refresh(String empName, String empStr) {
        idTvSalesman.setText(empName + "");
        idTvSalesman.setTextColor(getResources().getColor(R.color.wjx_content_txt_black_right));
        employeeStr = empStr;
    }

    @Override
    public void getString(String content) {
        showProgressDialog("请稍等，正在添加会员");
        initAddMember(activate_amount + "", content);
    }


    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        switch (i) {
            case R.id.id_rbtn_1:
                if (webFragment != null) {
                    transaction.hide(webFragment);
                }
                idMultipleStatusView.setVisibility(View.VISIBLE);
                ButtonRight.setVisibility(View.VISIBLE);
                frameLayout.setVisibility(View.GONE);
                idView1.setBackgroundColor(getResources().getColor(R.color.wjx_title_bg_next));
                idView2.setBackgroundColor(getResources().getColor(R.color.bottom_rgb_bule_false));
                break;
            case R.id.id_rbtn_2:
                idMultipleStatusView.setVisibility(View.GONE);
                ButtonRight.setVisibility(View.GONE);
                frameLayout.setVisibility(View.VISIBLE);
                idView1.setBackgroundColor(getResources().getColor(R.color.bottom_rgb_bule_false));
                idView2.setBackgroundColor(getResources().getColor(R.color.wjx_title_bg_next));
                if (webFragment == null) {
                    webFragment = WebFragment.newInstance("http://m.hfwjx.com");
                    transaction.add(R.id.fragment_container, webFragment, null);
                } else {
                    transaction.show(webFragment);
                }
                transaction.commitAllowingStateLoss();
                break;
        }
    }
}
